package com.hz.eduService.controller;

import com.hz.apiService.model.request.ApiResponse;
import com.hz.eduService.domain.UserCourse;
import com.hz.eduService.service.UserCourseService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiiiYiAn
 * @version 1.0
 * @createDate 2023-09-24 11:35
 * @projectName SchoolServicePlatformFinal
 * @className EduStudentController
 * @description 控制器 - 学生课程分数管理
 */
@RestController
@RequestMapping("/edu-student")
@RequiredArgsConstructor  // 使用构造器自动注入

public class EduStudentController {

    private final UserCourseService userCourseService;


    @PostMapping("/apply-re-exam")
    public String applyReExam(@RequestParam("id") Integer id, @RequestParam("userScore") Integer userScore, @RequestParam("passScore") Integer passScore) {
        return userCourseService.applyReExam(id, userScore, passScore) ? ApiResponse.ok("成绩通过，不用补考！") : ApiResponse.ok("申请成功！");
    }


    @PostMapping("/my-score")
    public String viewCourse(@RequestParam("id") Integer id) {
        UserCourse userCourse = userCourseService.myScore(id);
        return userCourse != null ? ApiResponse.ok(userCourse) : ApiResponse.intError();
    }

}
